package com.jwell.panrank.ui.activity

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.jwell.cargoapp.ui.base.MVPBaseActivity
import com.jwell.panrank.R
import com.jwell.panrank.contract.ElectronicPoundInfoContract
import com.jwell.panrank.entity.ElectronicePoundBean
import com.jwell.panrank.presenter.ElectronicPoundInfoPresenter
import com.jwell.panrank.tools.StringUtils
import kotlinx.android.synthetic.main.activity_electronic_pound_info.*

/**
 * 电子磅单详情
 */
class ElectronicPoundInfoActivity : MVPBaseActivity<ElectronicPoundInfoPresenter>(), ElectronicPoundInfoContract.View {
    private var data: ElectronicePoundBean? = null
    override fun createPresenter(): ElectronicPoundInfoPresenter? {
        return ElectronicPoundInfoPresenter()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_electronic_pound_info)
        initToolBar("磅单详情", true, null)
        intent?.extras?.let {
            data = it.getSerializable("itemData") as ElectronicePoundBean
        }
        setData()
        btn.setOnClickListener {
            val intent = Intent(this, LookElectronicPoundActivity::class.java)
            val bundle = Bundle()
            bundle.putSerializable("data", data)
            intent.putExtras(bundle)
            startActivity(intent)
        }
    }

    private fun setData() {
        data?.let {
            text_code.text = it.forBillCode ?: ""
            text_measurementTypeName.text = it.measurementTypeName ?: ""
            text_providerName.text = it.supplierName ?: ""
            text_goodsName.text = it.materialName ?: ""
            text_sendCom.text = it.forwardingUnit ?: ""
            text_receiptCom.text = it.receivingUnit ?: ""
            var str = StringBuffer()
            str.append(it.driverName ?: "")
            if ("" != str.toString() && it.driverPhone != null) {
                str.append("/")
            }
            str.append(it.driverPhone ?: "")
            text_driverInfo.text = str
            text_carNum.text = it.carNum ?: ""
            text_grossWt.text = it.grossWt.toString() + "吨"
            text_tareWt.text = it.tareWt.toString() + "吨"
            text_netWt.text = it.netWt.toString() + "吨"
            text_carMeasurePlaceDescr.text = it.carMeasurePlaceDescr ?: ""
            text_carMeasurePlaceDescr.text = it.carMeasurePlaceDescr ?: ""
            text_carMeasureByDescr.text = it.carMeasureByDescr ?: ""
            text_weightNo.text = it.weightNo ?: ""
            text_HEAVY_CAR_WEIGHT_ROOM.text = it.heavY_CAR_WEIGHT_ROOM ?: ""
            text_carMeasureTime.text = StringUtils.getInstance()
                    .setModal(StringUtils.TIME_TYPE_3)
                    .regularization(it.carMeasureTime, "T", " ")
            when (it.measurementType) {
                3 -> {
                    ll_carrierName.visibility = View.VISIBLE
                }
                else -> {
                    ll_carrierName.visibility = View.GONE
                }
            }
        }
    }
}
